home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / xlib.zip / MINI.C < prev    next >
C/C++ Source or Header  |  1987-07-07  |  2KB  |  132 lines

  1. #include    <stdio.h>
  2. #include    <dos.h>
  3.  
  4. int        t1stack[512];
  5. int        lastch;
  6.  
  7. /*
  8.  *    mini terminal.
  9.  *
  10.  *    a very few featured terminal program.
  11.  */
  12.  
  13. int        comport;
  14.  
  15. kbsvc()
  16. {
  17.     t_signal(0);        /* signal keyboard hit */
  18.     return 0;            /* chain on */
  19. }
  20.  
  21. int    kgetc()
  22. {
  23.     union REGS    r;
  24.     
  25.     for(;;)
  26.     {
  27.         r.h.ah = 0x0b;
  28.         intdos(&r,&r);
  29.         if( r.h.al != 0 )
  30.         {
  31.             return getch();
  32.         }
  33.         t_wait(0);
  34.     }
  35. }
  36.  
  37. task1()
  38. {
  39.     int        c;
  40.     
  41.     for(;;)
  42.     {
  43.         c = kgetc();
  44.         if( c == 0 )
  45.         {
  46.             kgetc();    /* get rid of extra key */
  47.             cclose(comport);
  48.             int_restore(9);
  49.             exit(0);
  50.         }
  51.         cputc(comport,c);
  52.     }
  53. }
  54.  
  55. int    getnum()
  56. {
  57.     int        i;
  58.     
  59.     i = 0;
  60.     lastch = cgetc(comport);
  61.     while( isdigit(lastch) )
  62.     {
  63.         i = i * 10 + (lastch - '0');
  64.         lastch = cgetc(comport);
  65.     }
  66.     return i;
  67. }
  68.  
  69. escseq()
  70. {
  71.     int        p1, p2, c;
  72.     
  73.     p1 = 0;
  74.     p2 = 0;
  75.     if( cgetc(comport) == '[' )
  76.     {
  77.         p1 = getnum();
  78.         if( lastch == ',' || lastch == ';' )
  79.         {
  80.             p2 = getnum();
  81.         }
  82.         switch( lastch )
  83.         {
  84.             case 'H': case 'f':
  85.                 disp_move(p1,p2);
  86.                 break;
  87.             
  88.             case 'J':
  89.                 disp_move(0,0);
  90.                 disp_eeop();
  91.                 break;
  92.             
  93.             case 'K':
  94.                 disp_eeol();
  95.                 break;
  96.         }
  97.     }
  98.     disp_flush();
  99. }
  100.  
  101. main()
  102. {
  103.     int        c;
  104.  
  105.     comport = copen(0,512,512);
  106.     if( comport < 0 )
  107.     {
  108.         printf("cant open com port\n");
  109.         exit(1);
  110.     }
  111.     cbaud(comport,1200);
  112.     cmode(comport,'n',8,1);
  113.  
  114.     disp_open();
  115.     int_intercept(9,kbsvc,256);
  116.     t_create(1,task1,t1stack,sizeof(t1stack));
  117.     
  118.     for(;;)
  119.     {
  120.         c = cgetc(comport);
  121.         if( c != '\033' )
  122.         {
  123.             disp_putc(c);
  124.             disp_flush();
  125.         }
  126.         else
  127.         {
  128.             escseq();
  129.         }
  130.     }
  131. }
  132.